# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=zstandard
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.21.0
pkgrel=2
pkgdesc='Python bindings to the Zstandard (zstd) compression library (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/indygreg/python-zstandard"
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-hypothesis")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-cffi")
options=('!emptydirs')
source=("https://github.com/indygreg/python-zstandard/archive/$pkgver.tar.gz")
sha256sums=('15adc6bfa629d48b0bb658e9eae94c484adb66a28738fa780478eebeb41599a5')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "python-${_realname}-$pkgver" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  sed -i 's,if compiler.compiler_type == "unix",if compiler.compiler_type == "mingw32",g' make_cffi.py
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build --inplace | warning "Tests failed"
  ${MINGW_PREFIX}/bin/python setup.py test | warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
